package com.yyk.yykywd.mvvm.model

import com.yyk.yykywd.base.BaseResponse
import com.yyk.yykywd.getNewMap
import com.yyk.yykywd.http.ApiService
import com.yyk.yykywd.mvvm.entity.WorkNumBean
import com.yyk.yykywd.putSign
import com.yyk.yykywd.putUserId
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers

/**
 * 文件描述：
 * Created by guo on 2019-11-27.
 */
class WorkModel {
    fun getWorkList(getWork: GetWork) {
        val newMap = getNewMap()
        putUserId(newMap)
        putSign(newMap)
        ApiService.getInstance().api.postWorkList(newMap)
                .subscribeOn(Schedulers.io()) //调度线程
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io()) //取消订阅
                .subscribe(object : Observer<WorkNumBean> {
                    override fun onComplete() {
                    }

                    override fun onSubscribe(d: Disposable?) {
                    }

                    override fun onNext(t: WorkNumBean) {
                        getWork.getInfo(t)
                    }

                    override fun onError(e: Throwable) {
                        getWork.onError(e.toString())
                    }

                })
    }

    interface GetWork : BaseResponse {
        fun getInfo(info: WorkNumBean)
    }

}